<template>
  <div class="home">
    <header>
      <p>
        宏烨找房
        <span>
          <img src="../img/2.gif" alt />
        </span>
      </p>
      <div class="check">
        <select v-model="select">
          <option v-for="(item,index) in address" :key="index">{{item}}</option>
        </select>
        <input type="text" placeholder="请在这里输入区域/商圈" />
        <span><van-icon name="search" /></span>
      </div>
    </header>
    <main>
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <!-- swipe轮播 -->
      <div class="swipe">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item><img src="https://tse1-mm.cn.bing.net/th/id/R-C.379734615959587da40889af4afd4497?rik=ngrYSdmn92F1rg&riu=http%3a%2f%2fup.36992.com%2fpic%2f48%2fc7%2f7e%2f48c77e4cf4a7f3a6b707de7a6e92f946.jpg&ehk=mnau6Kt5j%2bhJTxLJ6sujHLhbj83elCuPy%2bV3l%2fuTXMs%3d&risl=&pid=ImgRaw&r=0" alt=""></van-swipe-item>
          <van-swipe-item><img src="https://tse1-mm.cn.bing.net/th/id/R-C.dc570e703115fc797634cc557671ecd8?rik=rAvCbh2%2baXqcrQ&riu=http%3a%2f%2fimage.qianye88.com%2fpic%2f252fd3579f7fcbf3acdd9ef554447674&ehk=KgeoCZXCX21%2bZmYsVg8%2bBck5XJCtDSlb%2b4WXi%2fRK6ZE%3d&risl=&pid=ImgRaw&r=0" alt=""></van-swipe-item>
          <van-swipe-item><img src="https://tse1-mm.cn.bing.net/th/id/R-C.63f0bb317e96ea2fd12ab656525f5bd6?rik=7y8rE9H3fmCzNw&riu=http%3a%2f%2ffile06.16sucai.com%2f2016%2f0313%2f5a59b9be5c939f707fb812385ae808a8.jpg&ehk=220ZuP9CwmzqO8rSjW3i7za0X0pgy2cesWc9MgbnUu8%3d&risl=&pid=ImgRaw&r=0" alt=""></van-swipe-item>
          <van-swipe-item><img src="https://tse1-mm.cn.bing.net/th/id/R-C.d1fa9042f8b9580cd1e94553bea30b5d?rik=OrgxH%2faLORzfBA&riu=http%3a%2f%2fpic.netbian.com%2fuploads%2fallimg%2f160712%2f205448-1468328088c6aa.jpg&ehk=U1IFwLQ%2f3QC3uNY262NNUAd%2fsJkfEQ9xqCEyNVKJFnI%3d&risl=&pid=ImgRaw&r=0" alt=""></van-swipe-item>
        </van-swipe>
      </div>

      <!-- 标签页 -->
      <div class="label">
        <dl @click="buy()">
          <dt>
            <img src="../img/3.gif" alt='' />
          </dt>
          <dd>买房</dd>
        </dl>
        <dl>
          <dt @click="rent()">
            <img src="../img/4.gif" alt />
          </dt>
          <dd>租房</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/5.gif" alt />
          </dt>
          <dd>求租</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/6.gif" alt />
          </dt>
          <dd>求购</dd>
        </dl>
        <dl @click="map()">
          <dt>
            <img src="../img/7.gif" alt />
          </dt>
          <dd>地图找房</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/8.gif" alt />
          </dt>
          <dd>资讯</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/9.gif" alt />
          </dt>
          <dd>楼市圈</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/10.gif" alt />
          </dt>
          <dd>经纪人</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/11.gif" alt />
          </dt>
          <dd>团购看房</dd>
        </dl>
        <dl>
          <dt>
            <img src="../img/12.gif" alt />
          </dt>
          <dd>直播看房</dd>
        </dl>
      </div>

      <!-- 资讯频道 -->
      <div class="information">
        <div class="top"><h3>楼市资讯</h3> <span>更多</span></div>
        <div class="tit">
          <ul>
            <li v-for="(item,index) in informationList" :key="index">
              <span>TOP {{index+1}}</span>
              {{item.tit}}
            </li>
          </ul>
        </div>
      </div>

      <!-- 热门楼盘 -->
      <div class="hot">
         <div class="top"><h3>热门楼盘</h3> <span>更多</span></div>
         <dl v-for="(item,index) in buyHouse" :key="index" @click="Detail(item.id)">
           <dt><img :src="item.url" alt=""></dt>
           <dd>
             <p class="head">{{item.tit}}</p>
             <p>{{item.word}}</p>
             <p><span class="sum">{{item.sum}}万</span> <span class="price">{{item.price}}元 / m</span></p>
             <p><button>小区</button></p>
           </dd>
         </dl>
      </div>

      <!-- 经纪人 -->
      <div class="agent">
        <div class="top"><h3>经纪人</h3> <span>更多</span></div>

        <div class="list">
          <dl v-for="(item,index) in agentList" :key="index">
            <dt><img :src="item.url" alt=""></dt>
            <dd>
              <p>{{item.name}}</p>
              <p><span>{{item.tit}}</span></p>
              <button> <span><van-icon name="chat-o" /></span> 资讯</button>
            </dd>
          </dl>
        </div>
      </div>

      <!-- 二手房 -->
       <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        >
      <div class="second-hand">
        <div class="top"><h3>二手房</h3> <span>更多</span></div>

         <dl v-for="(item,index) in buyHouse" :key="index">
           <dt><img src="../img/13.gif" alt=""></dt>
           <dd>
             <p class="head">{{item.tit}}</p>
             <p>{{item.word}}</p>
             <p><span class="sum">{{item.sum}}万</span> <span class="price">{{item.price}}元 / m</span></p>
             <p><button>小区</button></p>
           </dd>
         </dl>
      </div>
      </van-list>
      </van-pull-refresh>
    </main>
  </div>
</template>

<script>
import axios from 'axios'
import { log } from 'util';
export default {
  name: "home",
  data() {
    return {
      address: ["北京", "上海", "深圳","广东"],
      select: "上海",
      informationList:[
        {tit:"心悦尚城新房正在抢购心悦尚城新房正在抢购!"},
        {tit:"心悦尚城新房正在抢购心悦尚城新房正在抢购!"},
        {tit:"心悦尚城新房正在抢购心悦尚城新房正在抢购!"},
        {tit:"心悦尚城新房正在抢购心悦尚城新房正在抢购!"},
      ],
      buyHouse:[],
      agentList:[
        {
          name:'建发曹颖',
          tit:'建发·文翰府',
          url:'https://pic1.zhimg.com/v2-2da83ea230c18b01f29baafcfa99d292_r.jpg?source=1940ef5c'
        },
        {
          name:'朗诗-李晓彤',
          tit:'朗诗蔚蓝,朗诗-...',
          url:'https://tse1-mm.cn.bing.net/th/id/R-C.5be1895658803d0b338ad6398933bdac?rik=VyyHjMHY28ogfg&riu=http%3a%2f%2fwww.gx8899.com%2fuploads%2fallimg%2f2018010908%2ft1f1qmt3iof.jpg&ehk=DlLA7jCKqVZV921rWUHVrAyPgQCqDoIVHk90jAokc%2f0%3d&risl=&pid=ImgRaw&r=0'
        },
        {
          name:'学府名都-张三',
          tit:'华地,学府名都',
          url:'https://tse1-mm.cn.bing.net/th/id/R-C.c4c9a79fcd2ac69b03919202346754b4?rik=i9Bms6kwbuczuQ&riu=http%3a%2f%2fwww.2qqtouxiang.com%2fpic%2fTX9060_26.jpg&ehk=QCIIpPzZAAGNpJij3rZFgkwTw9HxkM7dTrDPHNO04e4%3d&risl=&pid=ImgRaw&r=0'
        },
      ],
      //下拉刷新
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  created(){
    //调用函数
    this.buyHouseList()
  },
  methods:{
    //渲染买新房数据
    buyHouseList(){
      axios({
        url:'/api/buyHouse'
      }).then(res => {
        console.log(res);
        
        if(res.data.code === 1){
          this.buyHouse = res.data.data
        }else{
          this.$router.push(`/login`)
        }
      })
    },

    //跳转买房
    buy() {
      this.$router.push(`/buyHouse`)
    },
    //跳转租房
    rent(){
      this.$router.push(`/rentHouse`)
    },
    //地图找房
    map(){
      this.$router.push(`/mapHouse`)
    },

    //下拉刷新
    onLoad() {
      setTimeout(() => {
        if (this.refreshing) {
          this.list = [];
          this.refreshing = false;
        }

        for (let i = 0; i < 3; i++) {
          this.list.push(this.list.length + 1);
        }
        this.loading = false;

        if (this.list.length >= 3) {
          this.finished = true;
        }
      }, 1000);
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },

    //详情
    Detail(id){
      this.$router.push(`/Detail/${id}`);
    }
  },
};
</script>

<style>


.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
  width: 375px;
  height: 150px;
}

.my-swipe .van-swipe-item img{
  width: 100%;
  height: 100%;
}

.home {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.home header {
  width: 100%;
  height: 90px;
  background-color: #2997fb;
}

.home header p {
  color: white;
  margin-top: 10px;
  margin-left: 15px;
}

.home header p span {
  float: right;
  margin-right: 10px;
}

.home header .check {
  width: 90%;
  height: 27px;
  background-color: rgba(255, 255, 255, 0.5);
  margin-top: 20px;
  margin-left: 5%;
  border-radius: 8px;
  display: flex;
}

.home header .check select{
  background-color: rgba(255, 255, 255, 0);
  border: none;
  outline: none;
  color: white;
}

.home header .check select option{
  color: black;
}

.home header .check input {
  flex: 1;
  background-color: rgba(255, 255, 255, 0);
  border: none;
  outline: none;
}

.home header .check i{
  font-size: 20px;
  color: white;
  margin-top: 3px;
  margin-right: 6px;
}

.home main {
  flex: 1;
  overflow-y: auto;
}

.home main .label{
  width: 100%;
  height: 200px;
  /* border: 1px solid #ccc; */
}

.home main .label dl {
  width: 20%;
  height: 80px;
  float: left;
  text-align: center;
  margin-top: 13px;
}

.home main .label dl dd{
   margin-top: 4px;
}

.home main .information{
  margin-top: 10px;
  width: 95%;
  height: 200px;
  /* border: 1px solid #ccc; */
}

.home main .information .top{
  float: left;
  width: 100%;
  height: 30px;
  /* border: 1px solid #ccc; */
  line-height: 30px;
}

.home main .information .top h3{
  display: inline-block;
  margin-left: 10px;
}

.home main .information .top span{
  float: right;
  color: #ccc;
}

.home main .information .tit{
  float: left;
  width: 94%;
  height: 150px;
  border: 1px solid #ccc;
  margin-left: 5%;
  border-radius: 7px;
}

.home main .information .tit li{
  font-size: 13px;
  margin-top: 16px;
}

.home main .information .tit li span{
  background-color: #f98384;
  color: white;
  display: inline-block;
  width: 40px;
  height: 18px;
  line-height: 18px;
  margin-left: 10px;
  border-radius: 3px;
}

.home main .hot{
  width: 100%;
  height: 590px;
  /* border: 1px solid #ccc; */
}

.home main .hot .top{
  float: left;
  width: 95%;
  height: 30px;
  /* border: 1px solid #ccc; */
  line-height: 30px;
}

.home main .hot .top h3{
  display: inline-block;
  margin-left: 10px;
}

.home main .hot .top span{
  float: right;
  color: #ccc;
}

.home main .hot dl{
  float: left;
  width: 100%;
  height: 100px;
  /* border-bottom: 1px solid #ccc; */
  display: flex;
  margin-top: 10px;
}

.home main .hot dl dt{
  width: 37%;
  grid-template: 100%;
  margin-left: 10px;
}

.home main .hot dl img{
  width: 100%;
  height: 100%;
}

.home main .hot dl dd p{
  font-size: 12px;
  padding: 4px 0;
  margin-left: 8px;
}


.home main .hot dl dd .head{
  font-weight: bold;
  font-size: 13px;
}

.home main .hot dl dd .sum{
  color: #ff9900;
  font-weight: bold;
}

.home main .hot dl dd .price{
  color: #b3b3b3;
}

.home main .hot dl dd button{
  width: 55px;
  height: 22px;
  border: none;
  background-color: #eef0ef;
}

.home main .agent{
  width: 100%;
  height: 230px;
  /* border:1px solid #ccc; */
  margin-top: 6px;
}

.home main .agent .top{
  float: left;
  width: 95%;
  height: 30px;
  /* border: 1px solid #ccc; */
  line-height: 30px;
}

.home main .agent .top h3{
  display: inline-block;
  margin-left: 10px;
}

.home main .agent .top span{
  float: right;
  color: #ccc;
}

.home main .agent .list{
  width: 100%;
}

.home main .agent .list dl{
  width: 30%;
  height: 180px;
  float: left;
  text-align: center;
  border: 1px solid #ccc;
  border-radius: 6px;
  margin-top: 10px;
  margin-left: 2%;
}

.home main .agent .list dl dt{
  width: 100%;
  height: 70px;
}

.home main .agent .list dl dt img{
  width: 70%;
  height: 100%;
  border-radius: 50%;
  margin-top: 10px;
}

.home main .agent .list dl dd{
 margin-top: 17px;
}

.home main .agent .list dl dd p{
  font-weight: bold;
  
}

.home main .agent .list dl dd span{
  color: #b3b3b3;
  font-size: 12px;
  font-weight: normal;
}

.home main .agent .list dl dd button{
  width: 75px;
  height: 25px;
  border: none;
  border-radius: 20px;
  margin-top: 20px;
  background-color: #f7776d;
  color: white;
  line-height: 25px;
}

.home main .agent .list dl dd button span{
  color: white;
}

.home main .second-hand{
  width: 100%;
  height: 590px;
  /* border: 1px solid #ccc; */
  margin-top: 10px;
}

.home main .second-hand .top{
  float: left;
  width: 95%;
  height: 30px;
  /* border: 1px solid #ccc; */
  line-height: 30px;
}

.home main .second-hand .top h3{
  display: inline-block;
  margin-left: 10px;
}

.home main .second-hand .top span{
  float: right;
  color: #ccc;
}

.home main .second-hand dl{
  float: left;
  width: 100%;
  height: 100px;
  /* border-bottom: 1px solid #ccc; */
  display: flex;
  margin-top: 10px;
}

.home main .second-hand dl dt{
  margin-left: 10px;
}

.home main .second-hand dl img{
  width: 100%;
  height: 100%;
}

.home main .second-hand dl dd p{
  font-size: 12px;
  padding: 4px 0;
  margin-left: 8px;
}


.home main .second-hand dl dd .head{
  font-weight: bold;
  font-size: 13px;
}

.home main .second-hand dl dd .sum{
  color: #ff9900;
  font-weight: bold;
}

.home main .second-hand dl dd .price{
  color: #b3b3b3;
}

.home main .second-hand dl dd button{
  width: 55px;
  height: 22px;
  border: none;
  background-color: #eef0ef;
}
</style>